package com.sike.javacore.serializer.serializable.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.nio.ByteBuffer;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserInfo implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;

    private String userName;

    private String nickName;

    public byte[] codeC() {
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        byte[] userNameBytes = this.userName.getBytes();
        buffer.putInt(userNameBytes.length);
        buffer.put(userNameBytes);
        byte[] nickNameBytes = this.nickName.getBytes();
        buffer.putInt(nickNameBytes.length);
        buffer.put(nickNameBytes);
        buffer.putLong(this.id);
        buffer.flip();
        byte[] result = new byte[buffer.remaining()];
        buffer.get(result);
        return result;
    }
}
